/* @(#)GSAllProviderPayAction.java
 * 
 *  Project:GS
 *  
 *  Modify  Information:
 *  ===============================================
 *   Author          Date            Description
 *  -------------- ---------------  ---------------
 *  Jenny  Li      2006-6-8          新增
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 *
 */
package com.hitrust.gs.action;

import java.util.HashMap;

import com.hitrust.gs.bean.GSOperatorBean;
import com.hitrust.gs.business.GSBalanceProcessor;
import com.hitrust.gs.business.GSOrderDeptInfoProcessor;
import com.hitrust.gs.form.GSBalanceManageQueryForm;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.util.exception.GSException;

/**
 * @author JennyLi
 *
 */
public class GSAllProviderPayAction extends GSBaseAction {

    /* (non-Javadoc)
     * @see com.hitrust.gs.service.GSBaseAction#execute(com.hitrust.gs.service.GSBaseForm)
     */
    public String execute(GSBaseForm aForm) throws Exception {
        GSBalanceManageQueryForm tForm = (GSBalanceManageQueryForm)aForm;
        try{
            String year = tForm.getBalanceYear();
            String month = tForm.getBalanceMonth();
            if(Integer.parseInt(month) < 10){
                month = "0" + month;
            }
            //取得结算月份
            String tBalanceYM = year + month;
            //取得当前操作员可查询的订货单位
            GSOperatorBean tOperBean = (GSOperatorBean)aForm.getSession().getAttribute(GSBaseConstants.LOGIN);
            GSOrderDeptInfoProcessor tProc = new GSOrderDeptInfoProcessor();
            HashMap tMap = tProc.getOrderDeptOfBusOper(tOperBean.getGs_oper_org_id());
            aForm.getRequest().setAttribute("orderdept",tMap);

            GSBalanceProcessor tBalProc = new GSBalanceProcessor();
            boolean tFlag = tBalProc.productAllPayInfoByMonth(tBalanceYM,tOperBean.getGs_oper_id());
            if(tFlag){
                tForm.getRequest().setAttribute("message","成功生成本月对所有供应商的应付款!");
            }else{
                tForm.getRequest().setAttribute("message","生成本月对所有供应商的应付款失败!");
            }
            
            tForm.getRequest().setAttribute("requery","true");
        }catch(GSException ge){
            if(ge.getCode().equals(GSException.E40016)){
                tForm.getRequest().setAttribute("requery","true");
                tForm.getRequest().setAttribute("message",GSException.E40016_MSG);
            }else if (ge.getCode().equals(GSException.E40017)){
                tForm.getRequest().setAttribute("requery","true");
                tForm.getRequest().setAttribute("message",GSException.E40017_MSG);
            }else if (ge.getCode().equals(GSException.E40018)){
                tForm.getRequest().setAttribute("requery","true");
                tForm.getRequest().setAttribute("message",GSException.E40018_MSG);
            }else if (ge.getCode().equals(GSException.E40019)){
                tForm.getRequest().setAttribute("requery","true");
                tForm.getRequest().setAttribute("message",GSException.E40019_MSG);
            }else{
                tForm.getRequest().setAttribute("action","A180201.do");
                throw ge;
            }
        }catch(Exception e){
            tForm.getRequest().setAttribute("action","A180201.do");
            throw e;
        }
        return GSBaseConstants.FORWARD_SUCCESS;
    }

}
